#pragma once

#include "Containers/Vector.h"
#include "Math/Math.h"
#include "Material/Material.h"


struct WHENGINE_API SVertex2D
{
    // SVertex2D(SVec2 InPos,SColor InColor)
    // :Position(InPos),UV(InColor)
    // {};

    SVertex2D(SVec2 InPos,SVec2 UV)
    :Position(InPos),UV(UV.X,UV.Y)
    {};

    SVertex2D()
    {
    }

    SVec2 Position;

    SVec2 UV;

    
};

class WHENGINE_API CTriangle2D
{
public:    
    //P1 p2 p3 is in clockwise
    CTriangle2D(SVec2 InP1,SVec2 UV1,SVec2 InP2,SVec2 UV2,SVec2 InP3,SVec2 UV3);

    CTriangle2D(SVertex2D InP1, SVertex2D InP2 ,SVertex2D InP3 );
    
    CTriangle2D(){}

    //storage Counterclockwise in memory,for vulkan paint 
    SVertex2D P1;
    SVertex2D P3;
    SVertex2D P2;
    


};


//a group of triangle shared the  same material and clip
class WHENGINE_API CWidgetTriangle2DBatch
{
public:    
    SRect NormalizedClip; 
    TSharedObjectPtr<RMaterial> Material;
    TVector<CTriangle2D> Triangles;

    ~CWidgetTriangle2DBatch(){};
};


#include "Material/Material.h"

class WHENGINE_API CQuadrilateral
{
public:    
    TVector<CTriangle2D> Triangles;

    TSharedObjectPtr<RMaterial> Material;

    //  p1          p2
    //    *********
    //    *       *
    //    *       *   
    //    ********* 
    //  p3          p4
    static std::unique_ptr<CQuadrilateral> CreateQuads(SVec2 P1,SVec2 UV1,SVec2 P2,SVec2 UV2,SVec2 P3,SVec2 UV3,SVec2 P4,SVec2 UV4,TSharedObjectPtr<RMaterial> InMaterial)
    {
        auto Quads=std::make_unique<CQuadrilateral>();

        Quads->Material=InMaterial;
        Quads->Triangles.Emplace(P1,UV1,P2,UV2,P3,UV3);
        Quads->Triangles.Emplace(P2,UV2,P4,UV4,P3,UV3);
        //Quads->Material=InMaterial;
      
        return Quads;
    }

    static TVector<CTriangle2D> CreateQuadsTriangles(SVec2 P1,SVec2 UV1,SVec2 P2,SVec2 UV2,SVec2 P3,SVec2 UV3,SVec2 P4,SVec2 UV4)
    {
        TVector<CTriangle2D> Ret={ CTriangle2D(P1,UV1,P2,UV2,P3,UV3) , CTriangle2D(P2,UV2,P4,UV4,P3,UV3) };
        return Ret;
    }

    // static std::unique_ptr<CQuadrilateral> CreateQuads(SVec2 P1,SVec2 P2,SVec2 P3,SVec2 P4,SColor Color)
    // {
    //     auto Quads=std::make_unique<CQuadrilateral>();
    //     Quads->Triangles.emplace_back(P1,P2,P3,Color);
    //     Quads->Triangles.emplace_back(P2,P4,P3,Color);
      
    //     return Quads;
    // }

};